import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:second_hand/pages/home/NavigatorHomePage.dart';
import 'package:second_hand/pages/welcome.dart';
import 'data/profile_data.dart';
import 'data/shared_preferences_service.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    Get.put(UserController());
    return GetMaterialApp(
      title: 'Flutter App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: FutureBuilder(
        future: SharedPreferencesService.isUserLoggedIn(),
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return const Scaffold(body: Center(child: CircularProgressIndicator()));
          } else if (snapshot.data == true) {
            return const NavigatorHomePage(); // 如果已登录，显示主页
          } else {
            return const WelcomePage(); // 如果未登录，显示欢迎页面
          }
        },
      ),
    );
  }
}